package com.travel.utils;

public class Page {
	//��ǰҳ
	private int cpage;
	//��ҳ��
	private int totalPage;
	//��һҳ
	private int prevPage;
	//��һҳ
	private int nextPage;
	//��ʼλ��
	private int startPage;
	//��ҳ��λ
	private int pageSize;
	//������
	private int count;
	
	public Page(String cpage,int pageSize, int count){
		//�������������
		this.pageSize = pageSize;
		this.count = count;
		//������ҳ��
		this.initTotalpge();
		//����ǰҳ
		this.initCpage(cpage);
		//������һҳ
		this.initPrevPage();
		//������һҳ
		this.initNextPage();
		//������ʼλ��
		this.initStartPage();
	}
	
	
	//������ʼλ��
	private void initStartPage() {

		int startPage = (cpage-1)*pageSize;
		this.startPage = startPage;
	}

	
	//������һҳ
	private void initNextPage() {

		if(cpage>=totalPage){
			this.nextPage = totalPage;
		}else{
			this.nextPage = cpage + 1;
		}
	}

	//������һҳ
	private void initPrevPage() {

		if(cpage<=1){
			this.prevPage=1;
		}else{
			this.prevPage=cpage-1;
		}
	}
	
	//����ǰҳ
	private void initCpage(String cpage) {

		//�����ǰҳ�ǿ� Ĭ����ת����һҳ
		if(cpage==null||"".equals(cpage)){
			cpage="1";
		}
		int c = Integer.valueOf(cpage);
		//�жϵ�ǰҳ������ҳ��
		if(c>totalPage){
			c=totalPage;
		}
		//�жϵ�ǰҳС��1ҳ
		if(c<1){
			c=1;
		}
		this.cpage=c;
	}

	//������ҳ��
	private void initTotalpge() {

		int totalPage = count/pageSize;
		if(count%pageSize!=0){
			totalPage++;
		}
		this.totalPage = totalPage;
	}


	public int getPage() {
		return cpage;
	}
	public void setPage(int cpage) {
		this.cpage = cpage;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getPrevPage() {
		return prevPage;
	}
	public void setPrevPage(int prevPage) {
		this.prevPage = prevPage;
	}
	public int getNextPage() {
		return nextPage;
	}
	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}
	public int getStartPage() {
		return startPage;
	}
	public void setStartPage(int startPage) {
		this.startPage = startPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	@Override
	public String toString() {
		return "Page [cpage=" + cpage + ", totalPage=" + totalPage + ", prevPage=" + prevPage + ", nextPage=" + nextPage
				+ ", startPage=" + startPage + ", pageSize=" + pageSize + ", count=" + count + "]";
	}
	
	
	
}
